﻿<visi:VisiPage x:Class="VNet.VisiSuite.VisiAdmin.Views.UserView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:visi="clr-namespace:VNet.VisiSuite.VisiAdmin.Controls"
        xmlns:vm="clr-namespace:VNet.VisiSuite.VisiAdmin.ViewModels" xmlns:c="clr-namespace:VNet.VisiSuite.VisiAdmin.Controls"
        xmlns:vuc="clr-namespace:VNet.VisiSuite.Controls;assembly=VNet.VisiSuite.Controls" xmlns:converter="clr-namespace:VNet.VisiSuite.VisiAdmin.Common.Converters"
        xmlns:helper="clr-namespace:VNet.VisiSuite.VisiAdmin.Common.Helpers" xmlns:dg="http://infragistics.com/DataPresenter" xmlns:igDock="http://infragistics.com/DockManager"
               xmlns:ig="http://schemas.infragistics.com/xaml"
               xmlns:system="clr-namespace:System;assembly=mscorlib"
               DataContext="{DynamicResource UserViewModel}" mc:Ignorable="d" d:DesignHeight="315.538" d:DesignWidth="809.91">
    <visi:VisiPage.Resources>
        <vm:UserViewModel x:Key="UserViewModel" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <converter:InvertBooleanConverter x:Key="InvertBooleanConverter" />
        <converter:InvertBooleanVisibilityConverter x:Key="InvertBooleanVisibilityConverter" />
        <converter:ObjectNullVisibilityConverter x:Key="ObjectNullVisibilityConverter" />
    </visi:VisiPage.Resources>
    <vuc:BusyIndicator IsBusy="{Binding IsBusy}">
        <Grid Focusable="False" Background="{StaticResource WhiteColor}">
            <igDock:XamDockManager PaneDragStarting="PaneDragStarting">
                <igDock:ContentPane Style="{StaticResource NoHeaderPane}">
                    <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="42" />
                        </Grid.RowDefinitions>

                        <!--Header-->
                        <c:Header2Control Grid.Row="0" Title="{Binding PageTitle}" LeftMenuIcons="{Binding TopLeftButtonIcons}" RightMenuIcons="{Binding TopRightButtonIcons}" />

                        <!--Body-->
                        <Grid Grid.Row="1">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>

                            <TextBlock Style="{StaticResource CaptionTextBlockStyle}" Grid.Row="0"
                                    Text="Select a user from the list below to edit it. Use the Add button to the right to add a new user" />

                            <Grid Grid.Row="1">
                                <dg:XamDataPresenter DataSource="{Binding Path=Users}" ActiveDataItem="{Binding SelectedUser}" Style="{StaticResource XamDataPresenterStyle}">
                                    <dg:XamDataPresenter.FieldSettings>
                                        <dg:FieldSettings AllowEdit="False" AllowRecordFiltering="True" LabelClickAction="SortByOneFieldOnly" />
                                    </dg:XamDataPresenter.FieldSettings>
                                    <dg:XamDataPresenter.FieldLayoutSettings>
                                        <dg:FieldLayoutSettings HeaderPrefixAreaDisplayMode="FieldChooserButton" AutoGenerateFields="False" />
                                    </dg:XamDataPresenter.FieldLayoutSettings>
                                    <dg:XamDataPresenter.FieldLayouts>
                                        <dg:FieldLayout>
                                            <dg:Field Name="FirstName" Label="First Name" />
                                            <dg:Field Name="LastName" Label="Last Name" />
                                            <dg:Field Name="Email" Label="Email" Width="*" />
                                            <dg:Field Name="Login" Label="Login" />
                                            <dg:Field Name="IsEnabled" Label="Enabled">
                                                <dg:Field.Settings>
                                                    <dg:FieldSettings CellValuePresenterStyle="{StaticResource CheckBoxStyleGrid}" />
                                                </dg:Field.Settings>
                                            </dg:Field>
                                            <dg:Field Name="IsEditPart" Label="Can Edit Parts">
                                                <dg:Field.Settings>
                                                    <dg:FieldSettings CellValuePresenterStyle="{StaticResource CheckBoxStyleGrid}" />
                                                </dg:Field.Settings>
                                            </dg:Field>
                                            <dg:Field Name="IsEditUsers" Label="Can Edit User">
                                                <dg:Field.Settings>
                                                    <dg:FieldSettings CellValuePresenterStyle="{StaticResource CheckBoxStyleGrid}" />
                                                </dg:Field.Settings>
                                            </dg:Field>
                                            <dg:Field Visibility="Collapsed" Name="CreatedByUser" Label="Created By" />
                                            <dg:Field Visibility="Collapsed" Name="CreatedDate" Label="Created Date" />
                                            <dg:Field Visibility="Collapsed" Name="LastUpdatedByUser" Label="Last Updated By" />
                                            <dg:Field Visibility="Collapsed" Name="LastUpdatedDate" Label="Last Updated Date" />
                                        </dg:FieldLayout>
                                    </dg:XamDataPresenter.FieldLayouts>
                                </dg:XamDataPresenter>
                            </Grid>
                        </Grid>
                        <!--Footer-->
                        <ContentControl Grid.Row="2" Template="{StaticResource FooterTemplate}" />
                    </Grid>
                </igDock:ContentPane>

                <igDock:XamDockManager.Panes>
                    <igDock:SplitPane igDock:XamDockManager.InitialLocation="DockedRight" Width="325" SplitterOrientation="Horizontal">
                        <igDock:ContentPane Header="User Properties" Style="{StaticResource RightPaneStyle}">
                            <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Visibility="{Binding CloneSelectedUser, Converter={StaticResource ObjectNullVisibilityConverter}}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                                <ig:XamPropertyGrid Grid.Row="1"  SelectedObject="{Binding CloneSelectedUser}" ScrollBarVisibility="Auto" FilterAreaVisibility="Collapsed" >
                                    <ig:XamPropertyGrid.ItemFilters>
                                        <ig:PropertyGridConditionGroup LogicalOperator="Or" >
                                            <ig:PropertyGridComparisonCondition  Operator="Equals"  OperandSource="CategoryName" Value="General" ></ig:PropertyGridComparisonCondition>
                                            <ig:PropertyGridComparisonCondition  Operator="Equals"  OperandSource="CategoryName" Value="Permissions" ></ig:PropertyGridComparisonCondition>
                                            <ig:PropertyGridComparisonCondition  Operator="Equals"  OperandSource="CategoryName" Value="Update History" ></ig:PropertyGridComparisonCondition>
                                        </ig:PropertyGridConditionGroup>
                                    </ig:XamPropertyGrid.ItemFilters>
                                    <ig:XamPropertyGrid.EditorDefinitions>
                                        <ig:PropertyGridEditorDefinition Category="General">
                                            <ig:PropertyGridEditorDefinition.TargetProperties>
                                                <system:String>Login</system:String>
                                            </ig:PropertyGridEditorDefinition.TargetProperties>
                                            <ig:PropertyGridEditorDefinition.EditTemplate>
                                                <DataTemplate>
                                                    <TextBox IsReadOnly="{Binding Source={StaticResource UserViewModel}, Mode=TwoWay, Path = CloneSelectedUser.IsAddNew, Converter={StaticResource InvertBooleanConverter}}" Text ="{Binding Value,Mode=TwoWay}"
                                                               vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary}" />
                                                </DataTemplate>
                                            </ig:PropertyGridEditorDefinition.EditTemplate>
                                        </ig:PropertyGridEditorDefinition>
                                        <ig:PropertyGridEditorDefinition Category="Update History">
                                            <ig:PropertyGridEditorDefinition.EditTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text ="{Binding Value}" Style="{StaticResource PropertyDataTextBlockStyle}"/>
                                                </DataTemplate>
                                            </ig:PropertyGridEditorDefinition.EditTemplate>
                                        </ig:PropertyGridEditorDefinition>
                                        <ig:PropertyGridEditorDefinition Category="General">
                                            <ig:PropertyGridEditorDefinition.TargetProperties>
                                                <system:String>Password</system:String>
                                                <system:String>PasswordConfirmed</system:String>
                                            </ig:PropertyGridEditorDefinition.TargetProperties>
                                            <ig:PropertyGridEditorDefinition.EditTemplate>
                                                <DataTemplate>
                                                    <PasswordBox Style="{StaticResource PropertyPasswordBoxStyle}" MaxLength="32" vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary}"
                                            helper:PasswordHelper.BindPassword="true" helper:PasswordHelper.BoundPassword="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors= True, NotifyOnValidationError=True}" />
                                                </DataTemplate>
                                            </ig:PropertyGridEditorDefinition.EditTemplate>
                                        </ig:PropertyGridEditorDefinition>
                                    </ig:XamPropertyGrid.EditorDefinitions>
                                </ig:XamPropertyGrid>

                                <!---->
<!--                                <TextBlock Text="First Name" Grid.Row="1" Style="{StaticResource PropertyTextBlockStyle}" />-->
                                <!--                                <TextBlock Text="Last Name" Grid.Row="3" Style="{StaticResource PropertyTextBlockStyle}" />-->
                                <!--                                <TextBlock Text="Email" Grid.Row="5" Style="{StaticResource PropertyTextBlockStyle}" />-->
                                <!--                                <TextBlock Text="Login" Grid.Row="7" Style="{StaticResource PropertyTextBlockStyle}" />-->
                                <!--                                <TextBlock Text="Password" Grid.Row="9" Style="{StaticResource PropertyTextBlockStyle}" />-->
                                <!--                                <TextBlock Text="Confirm Password" Grid.Row="11" Style="{StaticResource PropertyTextBlockStyle}" />-->
                                <!---->
<!--                                <TextBox Grid.Row="2" Style="{StaticResource PropertyTextBoxStyle}" MaxLength="30"-->
                                <!--                                        vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary,Mode=OneWay}"-->
                                <!--                                        Text="{Binding CloneSelectedUser.FirstName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors= True, NotifyOnValidationError=True,ValidatesOnExceptions=True}" />-->
                                <!--                                <TextBox Grid.Row="4" Style="{StaticResource PropertyTextBoxStyle}" MaxLength="30" vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary}"-->
                                <!--                                        Text="{Binding CloneSelectedUser.LastName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors= True, NotifyOnValidationError=True}" />-->
                                <!--                                <TextBox Grid.Row="6" Style="{StaticResource PropertyTextBoxStyle}" MaxLength="40" vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary}"-->
                                <!--                                        Text="{Binding CloneSelectedUser.Email, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors= True, NotifyOnValidationError=True}" />-->
                                <!--                                <TextBox Grid.Row="8" Style="{StaticResource PropertyTextBoxStyle}" MaxLength="32" IsEnabled="{Binding CloneSelectedUser.IsAddNew}"-->
                                <!--                                        vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary}"-->
                                <!--                                        Text="{Binding CloneSelectedUser.Login, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors= True, NotifyOnValidationError=True}" />-->
                                <!---->
<!--                                <PasswordBox Grid.Row="10" Style="{StaticResource PropertyPasswordBoxStyle}" MaxLength="40"-->
                                <!--                                        vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary}" helper:PasswordHelper.BindPassword="true"-->
                                <!--                                        helper:PasswordHelper.BoundPassword="{Binding CloneSelectedUser.Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors= True, NotifyOnValidationError=True}" />-->
                                <!--                                <PasswordBox Grid.Row="12" Style="{StaticResource PropertyPasswordBoxStyle}" MaxLength="40"-->
                                <!--                                        vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary}" helper:PasswordHelper.BindPassword="true"-->
                                <!--                                        helper:PasswordHelper.BoundPassword="{Binding CloneSelectedUser.PasswordConfirmed, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors= True, NotifyOnValidationError=True}" />-->
                                <!---->
<!--                                <CheckBox Grid.Row="13" IsChecked="{Binding CloneSelectedUser.IsEnabled}" Height="Auto" Content="Enabled" Style="{StaticResource PropertyCheckBoxStyle}" />-->
                                <!--                                <CheckBox Grid.Row="14" IsChecked="{Binding CloneSelectedUser.IsEditPart}" Height="Auto" Content="Can Edit Parts" Style="{StaticResource PropertyCheckBoxStyle}" />-->
                                <!--                                <CheckBox Grid.Row="15" IsChecked="{Binding CloneSelectedUser.IsEditUsers}" Height="Auto" Content="Can Edit Users" Style="{StaticResource PropertyCheckBoxStyle}" />-->
                                <!---->
<!--                                <StackPanel Grid.Row="16" Orientation="Horizontal">-->
                                <!--                                    <TextBlock Text="Created By:" Style="{StaticResource PropertyTextBlockStyle}" VerticalAlignment="Center" />-->
                                <!--                                    <TextBlock Text="{Binding CloneSelectedUser.CreatedByUser}" Style="{StaticResource PropertyDataTextBlockStyle}" VerticalAlignment="Center" />-->
                                <!--                                </StackPanel>-->
                                <!---->
<!--                                <StackPanel Grid.Row="17" Orientation="Horizontal">-->
                                <!--                                    <TextBlock Text="Created Date:" Style="{StaticResource PropertyTextBlockStyle}" VerticalAlignment="Center" />-->
                                <!--                                    <TextBlock Text="{Binding CloneSelectedUser.CreatedDate}" Style="{StaticResource PropertyDataTextBlockStyle}" VerticalAlignment="Center" />-->
                                <!--                                </StackPanel>-->
                                <!---->
<!--                                <StackPanel Grid.Row="18" Orientation="Horizontal">-->
                                <!--                                    <TextBlock Text="Last Updated By:" Style="{StaticResource PropertyTextBlockStyle}" VerticalAlignment="Center" />-->
                                <!--                                    <TextBlock Text="{Binding CloneSelectedUser.LastUpdatedByUser}" Style="{StaticResource PropertyDataTextBlockStyle}" VerticalAlignment="Center" />-->
                                <!--                                </StackPanel>-->
                                <!--                                <StackPanel Grid.Row="19" Orientation="Horizontal">-->
                                <!--                                    <TextBlock Text="Last Updated Date:" Style="{StaticResource PropertyTextBlockStyle}" VerticalAlignment="Center" />-->
                                <!--                                    <TextBlock Text="{Binding CloneSelectedUser.LastUpdatedDate}" Style="{StaticResource PropertyDataTextBlockStyle}" VerticalAlignment="Center" />-->
                                <!--                                </StackPanel>-->

                                <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
                                    <Button Content="Save" Style="{StaticResource PropertyButtonStyle}" Command="{Binding SaveCommand}" IsEnabled="{Binding CloneSelectedUser.IsChange}" />
                                    <Button Content="Cancel" Style="{StaticResource PropertyButtonStyle}" Command="{Binding CancelCommand}" IsEnabled="{Binding CloneSelectedUser.IsCancelEnable}" />
                                    <Button Style="{StaticResource PropertyButtonStyle}" Content="Delete" Command="{Binding DeleteCommand}"
                                                Visibility="{Binding CloneSelectedUser.IsAddNew,Converter={StaticResource InvertBooleanVisibilityConverter},ConverterParameter=Collapsed}" />
                                </StackPanel>

                                <StackPanel Grid.Row="3">
                                    <vuc:ValidationSummary DataContext="{Binding Path=ValidationObject, Mode=TwoWay}"  x:Name="validationSummary" />
                                    <TextBlock TextWrapping="Wrap" Text="{Binding CloneSelectedUser.ErrorMessage}" Style="{StaticResource ErrorTextBlockStyle}" />
                                </StackPanel>
                            </Grid>
                        </igDock:ContentPane>
                    </igDock:SplitPane>
                </igDock:XamDockManager.Panes>
            </igDock:XamDockManager>
        </Grid>
    </vuc:BusyIndicator>
</visi:VisiPage>
